package com.gmu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gmu.pojo.TblDoctorAddress;
import com.gmu.mapper.TblDoctorAddressMapper;
import com.gmu.service.TblDoctorAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 医护人员活动地点表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-07-24
 */
@Service
public class TblDoctorAddressServiceImpl extends ServiceImpl<TblDoctorAddressMapper, TblDoctorAddress> implements TblDoctorAddressService {
    @Autowired
    private TblDoctorAddressMapper doctorAddressMapper;

    /**
     * 分页
     *
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public IPage<TblDoctorAddress> getPages(int currentPage, int pageSize) {
        IPage<TblDoctorAddress> page = new Page<>(currentPage, pageSize);
        return doctorAddressMapper.selectPage(page, null);
    }

    /**
     * 可以对开始时间和结束时间模糊查询
     *
     * @param currentPage
     * @param pageSize
     * @param doctorAddress
     * @return
     */
    @Override
    public IPage<TblDoctorAddress> getByPage(int currentPage, int pageSize, TblDoctorAddress doctorAddress) {
        LambdaQueryWrapper<TblDoctorAddress> queryWrapper = new LambdaQueryWrapper<TblDoctorAddress>();
        queryWrapper.like(Strings.isNullOrEmpty(doctorAddress.getActivitiesBeginTime().toString()), TblDoctorAddress::getActivitiesBeginTime, doctorAddress.getActivitiesBeginTime());
        queryWrapper.like(Strings.isNullOrEmpty(doctorAddress.getActivitiesEndTime().toString()), TblDoctorAddress::getActivitiesEndTime, doctorAddress.getActivitiesEndTime());
        IPage<TblDoctorAddress> page = new Page<>();
        return doctorAddressMapper.selectPage(page, queryWrapper);
    }
}
